/*
* linux-3.0.8/drivers/video/backlight/gt2440_backlightdev.c
*/

#include <linux/module.h>
#include <linux/ioport.h>
#include <linux/io.h>
#include <linux/platform_device.h>
#include <linux/init.h>
#include <linux/gpio.h>


#include <asm/mach-types.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <mach/hardware.h>
#include <mach/regs-gpio.h>


#include "gt2440_bl.h"


static int gt2440_backlight_pin_init(struct device *dev)
{
	int ret;
	ret = gpio_request(S3C2410_GPB(0), "Backlight");
	if (ret) {
		printk(KERN_ERR "failed to request GPD for PWM-OUT 0\n");
		return ret;
	}
	s3c_gpio_cfgpin(S3C2410_GPB(0), S3C_GPIO_SFN(2));
	return 0;
}

static void gt2440_backlight_pin_exit(struct device *dev)
{
	s3c_gpio_cfgpin(S3C2410_GPB(0), S3C_GPIO_OUTPUT);
	s3c2410_gpio_setpin(S3C2410_GPB(0), 0); /* gt2440 add: stop */
	gpio_free(S3C2410_GPB(0));
}

static struct gt2440_backlight_platdata gt2440_backlight_pdata = {
	.pwm_id		= 0,
	.max_brightness	= 255,
	.dft_brightness	= 10,
	.pwm_period_ns	= 78770,
	.init		= gt2440_backlight_pin_init,
	.exit		= gt2440_backlight_pin_exit,
};


static struct resource gt2440_timer0_resource[] = {
	[0] = {
		.start = IRQ_TIMER0,
		.end   = IRQ_TIMER0,
		.flags = IORESOURCE_IRQ,
	},
};

/***** backlight platform device *****/
static void gt2440_platform_device_release(struct device *dev){}

static struct platform_device gt2440_timer0_device= {
	.name		= "s3c24xx-pwm",
	.id		= 0,
	.num_resources	  = ARRAY_SIZE(gt2440_timer0_resource),
	.resource	  = gt2440_timer0_resource,
	.dev		= {
		.release = gt2440_platform_device_release,
	},
};

/***** timer0 platform device *****/
static struct platform_device gt2440_backlight_device = {
	.name = PLAT_DEVICE_NAME,
	.id = -1,
	//.num_resources	  = ARRAY_SIZE(gt2440_backlight_resource),
	//.resource	  = gt2440_backlight_resource,
	.dev		= {
		.parent = &gt2440_timer0_device.dev,
		.release = gt2440_platform_device_release,
		.platform_data = &gt2440_backlight_pdata,
	},
};


static int __init gt2440_backlightdev_init(void)
{	dprintk("gt2440_backlightdev_init()\n");
	int ret = 0;
	ret = platform_device_register(&gt2440_timer0_device);
	if(ret < 0)
		return ret;
	ret = platform_device_register(&gt2440_backlight_device);
	if(ret < 0){
		platform_device_unregister(&gt2440_timer0_device);;
	}
	return ret;
}
static void __exit gt2440_backlightdev_exit(void)
{	dprintk("gt2440_backlightdev_exit()\n");
	platform_device_unregister(&gt2440_backlight_device);
	platform_device_unregister(&gt2440_timer0_device);
}

module_init(gt2440_backlightdev_init);
module_exit(gt2440_backlightdev_exit);
MODULE_DESCRIPTION("GT2440	backlight Device Register Driver");
MODULE_AUTHOR("Liguang13579<1659890447@qq.com>");
MODULE_LICENSE("GPL v2");

